/**
    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) 2010  Sean Beecroft

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.

 * @version 1.10 2010-01-01
 * @author Sean Beecroft
 */

package yawiki.client.gui;

import java.awt.BorderLayout;
import java.awt.Insets;

import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JSeparator;
import javax.swing.JToolBar;
import javax.swing.text.StyledEditorKit;

import yawiki.client.actions.YStrikeThroughAction;
import yawiki.client.actions.YSubscriptAction;
import yawiki.client.actions.YSuperscriptAction;

public class YMenu extends JToolBar {
	
	boolean debug = false;
	
	public YMenu () 
	{
		//addWindowListener(new FrameListener());
		this.setFloatable(false);
		Insets margins = new Insets(0, 0, 0, 0);
		
		JMenuBar menuBar = new JMenuBar();
		add(menuBar, BorderLayout.NORTH);
		
		JMenu fileMenu = new JMenu("File");
		JMenu editMenu = new JMenu("Edit");
		JMenu insertMenu = new JMenu("Insert");
		JMenu helpMenu = new JMenu("Help");

		menuBar.add(fileMenu);
		menuBar.add(editMenu);
		menuBar.add(insertMenu);
		menuBar.add(helpMenu);

		JMenuItem newItem = new JMenuItem("New", new ImageIcon("media/new.gif"));
		JMenuItem openItem = new JMenuItem("Open", new ImageIcon("media/open.gif"));
		JMenuItem saveItem = new JMenuItem("Save", new ImageIcon("media/save.gif"));
		JMenuItem saveAsItem = new JMenuItem("Save As", new ImageIcon("media/save.gif"));
		JMenuItem exitItem = new JMenuItem("Exit", new ImageIcon("media/exit.gif"));

		//newItem.addActionListener(this);
		//openItem.addActionListener(this);
		//saveItem.addActionListener(this);
		//saveAsItem.addActionListener(this);
		//exitItem.addActionListener(this);

		fileMenu.add(newItem);
		fileMenu.add(new JSeparator());
		fileMenu.add(openItem);
		fileMenu.add(new JSeparator());
		fileMenu.add(saveItem);
		fileMenu.add(saveAsItem);
		fileMenu.add(new JSeparator());
		fileMenu.add(exitItem);

		JMenuItem undoItem = new JMenuItem();
		JMenuItem redoItem = new JMenuItem();
		JMenuItem cutItem = new JMenuItem();
		JMenuItem copyItem = new JMenuItem();
		JMenuItem pasteItem = new JMenuItem();
		JMenuItem clearItem = new JMenuItem("Clear");
		JMenuItem selectAllItem = new JMenuItem("Select All");
		JMenuItem insertBreaKItem = new JMenuItem();
		JMenuItem unorderedListItem = new JMenuItem();
		JMenuItem boldMenuItem = new JMenuItem();
		JMenuItem underlineMenuItem = new JMenuItem();
		JMenuItem italicMenuItem = new JMenuItem();
		JMenuItem subscriptMenuItem = new JMenuItem(new YSubscriptAction());
		JMenuItem superscriptMenuItem = new JMenuItem(new YSuperscriptAction());
		JMenuItem strikeThroughMenuItem = new JMenuItem(new YStrikeThroughAction());
		JMenuItem helpItem = new JMenuItem("Help Manual");
		JMenuItem shortcutsItem = new JMenuItem("Keyboard Shortcuts");
		JMenuItem aboutItem = new JMenuItem("About");
		JMenuItem leftAlignMenuItem = new JMenuItem();
		JMenuItem centerMenuItem = new JMenuItem();
		JMenuItem rightAlignMenuItem = new JMenuItem();
		JMenuItem welcomeItem = new JMenuItem("Welcome");
		

		
		undoItem.setText("Undo");
		redoItem.setText("Redo");
		
		cutItem.setText("Cut");
		copyItem.setText("Copy");
		pasteItem.setText("Paste");
		insertBreaKItem.setText("Break");
		
		undoItem.setIcon(new ImageIcon("media/undo.gif"));
		redoItem.setIcon(new ImageIcon("media/redo.gif"));

		clearItem.setIcon(new ImageIcon("media/clear.gif"));
		selectAllItem.setIcon(new ImageIcon("media/selectall.gif"));
		cutItem.setIcon(new ImageIcon("media/cut.gif"));
		copyItem.setIcon(new ImageIcon("media/copy.gif"));
		pasteItem.setIcon(new ImageIcon("media/paste.gif"));
		insertBreaKItem.setIcon(new ImageIcon("media/break.gif"));
		unorderedListItem.setIcon(new ImageIcon("media/bullets.gif"));
		helpItem.setIcon(new ImageIcon("media/help.gif"));
		welcomeItem.setIcon(new ImageIcon("media/welcome.gif"));

		//clearItem.addActionListener(this);
		//selectAllItem.addActionListener(this);


		editMenu.add(undoItem);
		editMenu.add(redoItem);
		editMenu.add(new JSeparator());
		editMenu.add(cutItem);
		editMenu.add(copyItem);
		editMenu.add(pasteItem);
		editMenu.add(new JSeparator());
		editMenu.add(clearItem);
		editMenu.add(new JSeparator());
		editMenu.add(selectAllItem);
		editMenu.add(insertBreaKItem);
		
		//editMenu.add(unorderedListItem);
		//editMenu.add(bulletItem);
		//editMenu.add(tableItem);
		//editMenu.add(rowItem);
		//editMenu.add(cellItem);
		//editMenu.add(linkItem);

		JMenu fontMenu = new JMenu("Font");
		fontMenu.setIcon( new ImageIcon("media/font.gif"));
		JMenu fontTypeMenu = new JMenu("Font Type");
		fontMenu.add(fontTypeMenu);

		String[] fontTypes = { "SansSerif", "Serif", "Monospaced", "Dialog",
				"DialogInput" };
		for (int i = 0; i < fontTypes.length; i++) {
			if (debug)
				System.out.println(fontTypes[i]);
			JMenuItem nextTypeItem = new JMenuItem(fontTypes[i]);
			nextTypeItem.setAction(new StyledEditorKit.FontFamilyAction(
					fontTypes[i], fontTypes[i]));
			fontTypeMenu.add(nextTypeItem);
		}

		
		JMenu fontSizeMenu = new JMenu("Font Size");
		fontMenu.add(fontSizeMenu);

		int[] fontSizes = { 6, 8, 10, 12, 14, 16, 20, 24, 32, 36, 48, 72 };
		for (int i = 0; i < fontSizes.length; i++) {
			if (debug)
				System.out.println(fontSizes[i]);
			JMenuItem nextSizeItem = new JMenuItem(String.valueOf(fontSizes[i]));
			nextSizeItem.setAction(new StyledEditorKit.FontSizeAction(String
					.valueOf(fontSizes[i]), fontSizes[i]));
			fontSizeMenu.add(nextSizeItem);
		}


		boldMenuItem.setText("Bold");
		underlineMenuItem.setText("Underline");
		italicMenuItem.setText("Italic");

		boldMenuItem.setIcon(new ImageIcon("media/b.gif"));
		underlineMenuItem.setIcon(new ImageIcon("media/u.gif"));
		italicMenuItem.setIcon(new ImageIcon("media/i.gif"));

		JMenu styleMenu = new JMenu("Style");
		
		styleMenu.add(boldMenuItem);
		styleMenu.add(underlineMenuItem);
		styleMenu.add(italicMenuItem);

		subscriptMenuItem.setText("Subscript");
		superscriptMenuItem.setText("Superscript");
		strikeThroughMenuItem.setText("StrikeThrough");

		subscriptMenuItem.setIcon(new ImageIcon("media/subscript.gif"));
		superscriptMenuItem.setIcon(new ImageIcon("media/superscript.gif"));
		strikeThroughMenuItem.setIcon(new ImageIcon("media/strikethrough.gif"));

		styleMenu.add(subscriptMenuItem);
		styleMenu.add(superscriptMenuItem);
		styleMenu.add(strikeThroughMenuItem);

		leftAlignMenuItem.setText("Left Align");
		centerMenuItem.setText("Center");
		rightAlignMenuItem.setText("Right Align");

		leftAlignMenuItem.setIcon(new ImageIcon("media/left.gif"));
		centerMenuItem.setIcon(new ImageIcon("media/center.gif"));
		rightAlignMenuItem.setIcon(new ImageIcon("media/right.gif"));

		JMenu alignMenu = new JMenu("Alignment");

		alignMenu.add(leftAlignMenuItem);
		alignMenu.add(centerMenuItem);
		alignMenu.add(rightAlignMenuItem);

		insertMenu.add(fontMenu);
		insertMenu.add(new JSeparator());
		insertMenu.add(styleMenu);
		insertMenu.add(new JSeparator());
		insertMenu.add(alignMenu);
		
		helpMenu.add(helpItem);
		helpMenu.add(welcomeItem);
		helpMenu.add(new JSeparator());
		helpMenu.add(shortcutsItem);
		helpMenu.add(new JSeparator());
		helpMenu.add(aboutItem);
		
	}
	
}